var token = new String;
var token_id="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx8d65e23df7356dbb&secret=38137f89a715feddd6291111985c4174";
$.getJSON(token_id,
    function (data) {
    token = data.access_token;
});
function userInformation() {
        // var redirect_uri = encodeURIComponent(window.location.href);
        // window.location.href="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx8d65e23df7356dbb&redirect_uri="+redirect_uri+"&response_type=code&scope=snsapi_login#wechat_redirect";
//登陆
    var uri = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=";
        //获取用户openid放进去ok了
    var openi = "&openid=oFdhE5xe145mwjzJPSFUBD2LV4rw";
    $.getJSON(uri +token+ openi,
        function (data) {
        var openid = data.openid;
        var name = data.nickname;
        var image = data.headimgurl;
        console.log(data);
            // 注册
            $.post("http://www.brandt-beer.com/app/appuser/register",
                {USER_NO: openid, NICKNAME: name, LOGO_IMG: image},
                function (data) {
                });
            //登陆
            $.post("http://www.brandt-beer.com/app/appuser/login",
                {USER_NO: openid},
                function (datab) {
                console.log(datab);
                    var session = datab.data;
                    window.location.href="mePage/mePage.html"+"?session="+session.SESSION_ID;
            });
        });
    }
//取消，关闭页面
function customClose(){
    if (confirm("您确定要关闭本页吗？")){
        window.opener=null;
        window.open('','_self');
        window.close();
    }
}
//    获取用户授权，重定向

// $.get("https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx8d65e23df7356dbb&redirect_uri=http://www.brandt-beer.com/static/app/bolanteBeer/general/index.html&response_type=code&scope=snsapi_base#wechat_redirect",
//     function (data) {
//
//     })